//
//  YYEComposeButton.swift
//  weibo14
//
//  Created by mac on 16/3/10.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class YYEComposeButton: UIButton {

    var menuInfo: YYEComposeMenuInfo?{
    
        didSet{
            self.setImage(UIImage(named: menuInfo!.icon!), forState: UIControlState.Normal)
            self.setTitle(menuInfo!.title!, forState: UIControlState.Normal)
        }
    }
    
    // Swift 去掉按钮的高亮效果
    override var highlighted: Bool {
        get{
            return false
        }
        set{
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupUI(){
    
        // 文字居中
        titleLabel?.textAlignment = .Center
        // 文字颜色
        setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        // 文字大小
        titleLabel?.font = UIFont.systemFontOfSize(16)
        // 让图片原样显示
        imageView?.contentMode = .Center
    }
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        let width = self.frame.width
        let height = self.frame.height

        imageView?.frame.origin = CGPointZero
        imageView?.frame.size = CGSizeMake(width, width)
        
        titleLabel?.frame.origin = CGPointMake(0, width)
        titleLabel?.frame.size = CGSizeMake(width, height - width)
    }
    
}
